import struct
import time
import sys
import redis

import struct
ip = '192.168.16.1'
connre = redis.Redis(ip)
connre.delete('dxdy')
def read(f,fno):
    FORMAT = 'llHHi'
    EVENT_SIZE = struct.calcsize(FORMAT)
    event = f.read(EVENT_SIZE)
    (tv_sec, tv_usec, type, code, value) = struct.unpack(FORMAT, event)

    if type != 0 or code != 0 or value != 0:
        ss = '%s#%s#%s#%s'%(fno,type,code,value)
        connre.rpush('dxdy',ss)
    else:
        pass

f = ["/dev/input/event8","/dev/input/event5","/dev/input/event6"]
fl = []
fno = {}
for no,i in enumerate(f):
    fn = open(i,'rb')
    fl.append(fn)
    fno[fn.fileno()] = no
import select
while True:
    r,w,e = select.select(fl,[],[])
    for i in r:
        read(i,fno[i.fileno()])